package org.batatasframework.support.type;

import java.util.ArrayList;
import java.util.List;

public class OptionalTypeMultiple extends OptionalType{
	
	@Override
	public String show(long value) {
		StringBuilder sb = new StringBuilder();
		for(OptionalItem oi : sources){
			if(internalMatch(oi, value)){
				if(sb.length() > 0) sb.append(',');
				
				sb.append(oi.name);
			}
		}
		return sb.toString();
	}

	@Override
	public List<OptionalItem> find(long value) {
		List<OptionalItem> items = new ArrayList<>();
		for(OptionalItem oi : sources){
			if(internalMatch(oi, value)){
				items.add(oi);
			}
		}
		return items;
	}
	
	@Override
	protected boolean internalMatch(OptionalItem item, long optionValue) {
		return (optionValue & (1 << item.value)) > 0;
	}

	@Override
	public boolean isMultiple() {
		return true;
	}
}
